package com.ming_za.odupdaterserver.core.sqlite.domain;

import java.io.Serial;
import java.io.Serializable;
import java.util.Date;

import lombok.Data;

/**
 * 资源信息对象
 * 存储资源的位置等信息
 */
@Data
public class Res implements Serializable {
    /**
     * 资源id，雪花算法
     */
    private Long resid;

    /**
     * 本地存储的地址，包括资源存储文件夹
     */
    private String localPath;

    /**
     * 存在于客户端的地址
     */
    private String clientPath;

    /**
     * 是否为必须更新
     */
    private Boolean necessary;

    /**
     * 是否为删除，如果为true则忽略{@link #localPath}
     */
    private Boolean delete;

    /**
     * 更新上传时间
     */
    private Date time;

    /**
     * 资源标签,0->default,多个标签符合（不融合父级）
     */
    private Long label;

    /**
     * 类型，当前支持0,1。
     * 0为普通类型，可能不存入数据库，
     * 1为MC mod类型
     */
    private int type = 0;

    /**
     * 额外数据，一般是json格式
     */
    private String data = null;

    @Serial
    private static final long serialVersionUID = 1L;

    @Override
    public boolean equals(Object that) {
        if (this == that) {
            return true;
        }
        if (that == null) {
            return false;
        }
        if (getClass() != that.getClass()) {
            return false;
        }
        Res other = (Res) that;
        return (this.getResid() == null ? other.getResid() == null : this.getResid().equals(other.getResid()))
            && (this.getLocalPath() == null ? other.getLocalPath() == null : this.getLocalPath().equals(other.getLocalPath()))
            && (this.getClientPath() == null ? other.getClientPath() == null : this.getClientPath().equals(other.getClientPath()))
            && (this.getNecessary() == null ? other.getNecessary() == null : this.getNecessary().equals(other.getNecessary()))
            && (this.getDelete() == null ? other.getDelete() == null : this.getDelete().equals(other.getDelete()));
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((getResid() == null) ? 0 : getResid().hashCode());
        result = prime * result + ((getLocalPath() == null) ? 0 : getLocalPath().hashCode());
        result = prime * result + ((getClientPath() == null) ? 0 : getClientPath().hashCode());
        result = prime * result + ((getNecessary() == null) ? 0 : getNecessary().hashCode());
        result = prime * result + ((getDelete() == null) ? 0 : getDelete().hashCode());
        return result;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append(" [");
        sb.append("Hash = ").append(hashCode());
        sb.append(", resid=").append(resid);
        sb.append(", localPath=").append(localPath);
        sb.append(", clientPath=").append(clientPath);
        sb.append(", necessary=").append(necessary);
        sb.append(", delete=").append(delete);
        sb.append(", serialVersionUID=").append(serialVersionUID);
        sb.append("]");
        return sb.toString();
    }
}